import { Component } from '@angular/core';
import { _HttpClient, ModalHelper } from '@delon/theme';
import { NzMessageService } from 'ng-zorro-antd/message';
import { SysUserEditComponent } from './edit/edit.component';
import { SysUserService } from '@api/sys/service/sysUser.service';
import { SListComponent } from '../../common/list/slist.component';
import { SysUser } from '@api/sys/model/sysUser.model';
import { SysKeyValueService } from '@api/sys/service/sysKeyValue.service';

@Component({
  selector: 'app-sys-user',
  templateUrl: '../../common/list/list.component.html',
})
export class SysUserComponent extends SListComponent<SysUser, String> {
  constructor(
    public http: _HttpClient,
    public modal: ModalHelper,
    public sysUserService: SysUserService,
    public msgSrv: NzMessageService,
    public keyValueService: SysKeyValueService,
  ) {
    super(http, modal, sysUserService, msgSrv, SysUserEditComponent);
    this.searchSchema = {
      properties: {
        username: {
          type: 'string',
          title: '用户名',
        },
        petname: {
          type: 'string',
          title: '昵称',
        },
        realname: {
          type: 'string',
          title: '真实姓名',
        },
        genderArray: {
          type: 'string',
          title: '性别',
          ui: {
            widget: 'checkbox',
            asyncData: () => this.keyValueService.getSFSchemaEnumTypesByType('/USER/GENDER'),
          },
        },
      },
    };

    this.columns = [
      { title: 'ID', index: 'id', type: 'checkbox' },
      { title: '用户名', index: 'username' },
      { title: '昵称', index: 'petname' },
      { title: '真实姓名', index: 'realname' },
      { title: '性别', index: 'genderName', render: 'columnSex' },
      { title: '生日', type: 'date', index: 'birthday' },
      { title: '电话', index: 'phone' },
      { title: '邮箱', index: 'email' },
      // { title: '头像', type: 'img', width: '50px', index: 'avatar' },
      { title: '创建时间', type: 'date', index: 'createdDate' },
      {
        title: '创建人',
        index: 'createdByName',
      },
      {
        title: '操作',
        width: 100,
        buttons: [
          // { text: '查看', click: (item: any) => `/form/${item.id}` },
          { icon: 'edit', type: 'static', modal: { component: SysUserEditComponent }, click: 'reload', tooltip: `编辑` },
          {
            tooltip: `删除`,
            icon: 'delete',
            type: 'del',
            pop: {
              title: '是否确定删除?',
              okType: 'danger',
              icon: 'star',
            },
            click: (record, _modal, comp) => this.delete(record, _modal, comp),
          },
        ],
      },
    ];
  }
}
